package com.ruoyi.StarStudio.Mapper;

import com.ruoyi.StarStudio.Domain.Device;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface DeviceMapper {

    @Select("select * from device")
    public List<Device> getAll();

    public List<Device> getList(Device device);

    @Select("select * from device where device_id = #{deviceId}")
    public Device getById(int deviceId);

    @Insert("insert into device values (null,#{device_name}, #{device_series_number},#{device_location}, #{device_status}, #{device_data}, #{device_updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "device_id", keyColumn = "device_id")
    public void add(Device device);

    @Insert("insert into zone_device values(#{zoneId},#{deviceId})")
    public void addToZone_Device(@Param("zoneId") int zoneId, @Param("deviceId") int deviceId);

    @Update("update device set device_name=#{device_name},device_series_number=#{device_series_number},device_location = #{device_location},device_status=#{device_status},device_data=#{device_data},device_updatetime=#{device_updateTime} where device_id = #{device_id}")
    public void update(Device device);

    @Delete("delete from device where device_id = #{deviceId}")
    public void delete(int deviceId);

    @Select("select * from device where device_series_number = #{device_series_number}")
    Device getBySeriesNumber(String device_series_number);

    @Select("select zd.zone_id from zone_device zd,device d where zd.device_id = d.device_id and d.device_series_number = #{device_series_number}")
    public int getZoneIDByDevice_series_number(String device_series_number);
}
